home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Format 1995 June
/
MacFormat 25.iso
/
Shareware City
/
Developers
/
ICProgKit1.0
/
Source
/
Libs
/
ICSubs.p
< prev
next >
Wrap
Text File
|
1994-11-27
|
2KB
|
97 lines
unit ICSubs;
interface
uses
{$ifc undefined THINK_Pascal}
Types,
{$endc}
ICTypes;
function ICMapErr (icerr: ICError): OSErr;
function ICGetPrefHandle (inst: ICInstance; key: Str255; var attr: ICAttr; var prefh: Handle): ICError;
function ICSetPrefHandle (inst: ICInstance; key: Str255; attr: ICAttr; prefh: Handle): ICError;
function ICGetPrefStr (inst: ICInstance; key: Str255; var attr: ICAttr; var str: Str255): ICError;
function ICSetPrefStr (inst: ICInstance; key: Str255; attr: ICAttr; str: Str255): ICError;
implementation
uses
{$ifc undefined THINK_Pascal}
Memory, Resources,
{$endc}
ICAPI;
function ICMapErr (icerr: ICError): OSErr;
begin
if (icerr < -32768) or (icerr > 32767) then begin
icerr := icInternalErr;
end; (* if *)
ICMapErr := icerr;
end; (* ICMapErr *)
function ICGetPrefHandle (inst: ICInstance; key: Str255; var attr: ICAttr; var prefh: Handle): ICError;
var
err: ICError;
prefsize: longint;
begin
prefh := nil;
prefsize := 0;
err := ICGetPref(inst, key, attr, nil, prefsize);
if err <> noErr then begin
prefsize := 0;
end; (* if *)
prefh := NewHandle(prefsize);
err := MemError;
if err = noErr then begin
HLock(prefh);
err := ICGetPref(inst, key, attr, prefh^, prefsize);
if err = icPrefNotFoundErr then begin
attr := 0;
err := noErr;
end; (* if *)
HUnlock(prefh);
end; (* if *)
if err <> noErr then begin
if prefh <> nil then begin
DisposeHandle(prefh);
end; (* if *)
prefh := nil;
end; (* if *)
ICGetPrefHandle := err;
end; (* ICGetPrefHandle *)
function ICSetPrefHandle (inst: ICInstance; key: Str255; attr: ICAttr; prefh: Handle): ICError;
var
s: SignedByte;
err: ICError;
begin
s := HGetState(prefh);
HLock(prefh);
err := ICSetPref(inst, key, attr, prefh^, GetHandleSize(prefh));
HSetState(prefh, s);
ICSetPrefHandle := err;
end; (* ICSetPrefHandle *)
{$PUSH}
{$R-}
function ICGetPrefStr (inst: ICInstance; key: Str255; var attr: ICAttr; var str: Str255): ICError;
var
err: ICError;
size: longint;
begin
size := 256;
err := ICGetPref(inst, key, attr, @str, size);
if err <> noErr then begin
str := '';
end; (* if *)
ICGetPrefStr := err;
end; (* ICGetPrefStr *)
function ICSetPrefStr (inst: ICInstance; key: Str255; attr: ICAttr; str: Str255): ICError;
begin
ICSetPrefStr := ICSetPref(inst, key, attr, @str, length(str) + 1);
end; (* ICSetPrefStr *)
{$POP}
end. (* ICSubs *)